<template>
  <page class="app-container">
    <!-- 过滤条件 begin-->
    <el-form :inline="true" class="filter-container">
      <el-form-item label="会员等级" prop="memberGroup">
        <member-group-select v-model="searchForm.memberGroup" :all="true"></member-group-select>
      </el-form-item>
      <el-form-item label="手机号" prop="mobile">
        <el-input v-model="searchForm.mobile" placeholder="手机号" clearable></el-input>
      </el-form-item>
      <el-form-item label="昵称/姓名" prop="name">
        <el-input v-model="searchForm.name" placeholder="微信昵称/姓名" clearable></el-input>
      </el-form-item>
      <el-form-item label="会员ID" prop="id">
        <el-input v-model="searchForm.id" placeholder="会员ID" style="width: 120px" clearable></el-input>
      </el-form-item>
      <el-form-item label="时间段">
        <el-date-picker
          v-model="time"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button class="filter-item" type="primary" icon="el-icon-search" @click="onSearch">查询
        </el-button>
      </el-form-item>
    </el-form>
    <!-- 过滤条件 end-->

    <!-- 表格 begin-->
    <el-table :data="list" style="width: 100%">
      <el-table-column prop="id" label="会员ID"></el-table-column>

      <el-table-column prop="userCode" label="会员编号" align="center" min-width="90"></el-table-column>

      <el-table-column label="会员等级">
        <template slot-scope="props">
          <el-tag>{{props.row.memberGroup | memberName}}</el-tag>
        </template>
      </el-table-column>

      <el-table-column align="left" label="头像">
        <template slot-scope="props">
          <m-img :src="props.row.head" ratio="1" style="width: 50px"/>
        </template>
      </el-table-column>

      <el-table-column prop="nick" label="昵称"></el-table-column>

      <el-table-column prop="realName" label="真实姓名"></el-table-column>

      <el-table-column prop="mobile" label="手机"></el-table-column>

      <el-table-column prop="integral" label="积分"></el-table-column>

      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="props">
          <el-button type="primary" size="small">修改详情</el-button>
          <el-button size="small">交易记录</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格 end-->

    <!--分页 begin-->
    <div class="pagination-container mt20">
      <el-pagination background @current-change="onPageChange" :current-page="searchForm.page" :page-size="limit"
                     layout="total, prev, pager, next, jumper" :total="total"></el-pagination>
    </div>
    <!--分页 begin-->

    <!--编辑 or 添加 弹窗 begin-->
    <el-dialog title="编辑" :visible.sync="dialogShow">
      <el-form ref="dataForm" :model="dataForm" label-position="left" label-width="70px"
               style='width: 400px; margin-left:50px;'>
        <el-form-item label="remark">
          <el-input placeholder="Please input" v-model="dataForm.input"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogShow = false">取消</el-button>
        <el-button type="primary" @click="onSubmit">确认</el-button>
      </div>
    </el-dialog>
    <!--编辑 or 添加 弹窗 begin-->
  </page>
</template>

<script>
  import {elValidate} from '@/utils/widget'
  import {timeMap} from '@/utils/widget'

  export default {
    name: 'memberList',
    data() {
      return {
        list: [],
        total: 0,
        limit: 0,
        listLoading: true,
        searchForm: {
          date1: null,
          date2: null,
          page: 1
        },
        dialogShow: false,
        dataForm: {}
      }
    },
    computed: {
      time: timeMap('searchForm.date1', 'searchForm.date2')
    },
    created() {
      this.getList()
    },
    methods: {
      // 增
      add() {

      },
      // 删
      del() {

      },
      // 获取列表
      async getList() {
        //this.listLoading = true
        let {total, list, limit} = await this.$get_list('admin/member/getUserByComdition', this.searchForm)
        Object.assign(this, {total, list, limit})
        document.documentElement.scrollTop = 0
      },
      // 更新数据
      update() {

      },
      // 搜索过滤
      onSearch() {
        this.searchForm.page = 1
        this.getList()
      },

      // 分页
      onPageChange(val) {
        this.searchForm.page = val
        this.getList()
      },

      onAdd() {
      },
      onDel() {
      },
      onUpdate() {
      },
      onDownload() {

      },
      async onSubmit() {
        await elValidate(this, 'dataForm')

        this.dialogShow = false
        await this.$nextTick()
        this.$refs.dataForm.resetFields()
      }
    }
  }
</script>
